package com.sphd.beautysalon.activitys;

import android.graphics.Bitmap;
import android.graphics.BitmapFactory;
import android.os.Bundle;
import android.support.v7.widget.Toolbar;
import android.view.View;
import android.widget.ImageView;
import android.widget.RelativeLayout;
import android.widget.TextView;

import com.sphd.beautysalon.base.RestaurantUrl;
import com.sphd.beautysalon.utils.EwmUtil;
import com.sphd.beautysalon.utils.updata.UpDataUtils;
import com.sphd.beautysalon.R;
import com.sphd.beautysalon.base.BaseActivity;

import butterknife.BindView;
import butterknife.ButterKnife;
import butterknife.OnClick;

/*
*
* 关于界面
* */
public class SettingActivity extends BaseActivity {

    @BindView(R.id.toolbar)
    Toolbar toolbar;
    @BindView(R.id.logo_erweima)
    ImageView logoErweima;
    @BindView(R.id.version)
    TextView version;
    @BindView(R.id.setting_update_layout)
    TextView settingUpdateLayout;
    @BindView(R.id.setting_feedback_layout)
    TextView settingFeedbackLayout;
    @BindView(R.id.setting_help_layout)
    TextView settingHelpLayout;
    @BindView(R.id.setting_message_layout)
    TextView settingMessageLayout;
    @BindView(R.id.content_setting)
    RelativeLayout contentSetting;
    EwmUtil ewmUtil;

    @Override
    protected void onCreate(Bundle savedInstanceState) {
        super.onCreate(savedInstanceState);
        setContentView(R.layout.activity_setting);
        ButterKnife.bind(this);
        initView();
        initEvent();
    }

    private void initEvent() {
        toolbar.setNavigationOnClickListener(v -> finish());
    }

    private void initView() {
        setTitleBar(toolbar, "关于");
        ewmUtil = new EwmUtil();
        creatEwm(RestaurantUrl.EWMDownload, R.mipmap.ic_launcher_small);
        try {
            version.setText("版本号v"+ UpDataUtils.getVersionName(context));
        } catch (Exception e) {
            e.printStackTrace();
        }

    }

    private void creatEwm(String url, int imageId) {
        Bitmap qrBitmap = ewmUtil.generateBitmap(url, 400, 400);
        Bitmap logoBitmap = BitmapFactory.decodeResource(getResources(), imageId);
        Bitmap bitmap = ewmUtil.addLogo(qrBitmap, logoBitmap);
        logoErweima.setImageBitmap(bitmap);
    }

    @OnClick({R.id.setting_update_layout, R.id.setting_feedback_layout, R.id.setting_help_layout, R.id.setting_message_layout})
    public void onClick(View view) {
        switch (view.getId()) {
            case R.id.setting_update_layout:
                UpDataUtils upDataUtils =new UpDataUtils(context,"");
                upDataUtils.checkUp("http://www.paybae.com/update/versionManager.xml");
//                upDataUtils.checkUp("http://restaurant.zhongxs.com/Restaurant/update/versionClient.xml");
                break;
            case R.id.setting_feedback_layout:
                toast("暂无开放此功能");
                break;
            case R.id.setting_help_layout:
                toast("暂无开放此功能");
                break;
            case R.id.setting_message_layout:
                toast("暂无开放此功能");
                break;
        }
    }
}
